﻿<?php

/**
 * Created by PhpStorm. User: ADun, Date: 14-10-15 下午10:11
 * Description:
 */
$openId=getCurrentUserOID();

if(empty($openId)) exit('参数错误');

$bm = new CUI数据中心(Page::m卖家中心_账目,$openId);


$语音列表 = $bm->生成有效链接('Seller17Voice_LessonsS',$_GET['state']);
$语音课程 = $bm->fc查语音课程($_GET['id']);
$语音课程报名人数 =pdo()->selectOne("SELECT COUNT('id') FROM `语音课程报名` WHERE `课程id` ='".$_GET['id']."' and `状态`='报名';");

$当前用户已报名 = $bm->get当前用户是否报名该课程($_GET['id']);

if(!$当前用户已报名) $当前用户已报名 =array('id'=>0,'状态'=>'取消报名');
if($当前用户已报名['状态']==='报名') $状态 = '取消报名';
else $状态 = '报名';


$注册 = $bm->生成有效链接('register',$_GET['state']);
$sql = "SELECT   `密码`  from `用户`  where id = ".$_SESSION['vo用户数据']['id'];
$个人信息 = pdo()->selectOne($sql);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no"/>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?= $语音课程['title']?></title>
    <link rel="stylesheet" href="../style/common.css?<?=版本?>">
       <style>
        .author p{font-size: 11pt; font-family: 华文楷体;}
    </style>
</head>

<body>
<div class="header">  <?php
    $认证 = $bm->生成有效链接('Seller18ZiLiao',$_GET['state']);
    $加入聊天 = $bm->生成有效链接('websocket',$_GET['state']);
    if($_SESSION['vo用户数据']['认证'] === '1'){
        echo '<a href="'.$认证.'" class="RzFalse"><span>立即认证 >></span></a>';}
    ?><a href="<?=$语音列表?>"   class="list">语音列表</a></div></div>
<div class="class_view">
    <div class="about">

        <div class="box"><div>授课时间</div><h2><?php echo (substr($语音课程['开始时间'],5,2))."月".( substr($语音课程['开始时间'],8,2))."日".( substr($语音课程['开始时间'],11,5)); ?></h2></div>
        <h1><?= $语音课程['title']?></h1>
    </div>

    <div class="avatar"><img src="<?php if($语音课程['头像']) echo $语音课程['头像']; else echo "../cache/card_img/top_index.jpg"; ?>" /><p style="color:#333;font-size: 14pt; font-family: 华文楷体; font-weight: bold;"><?=  $语音课程['name']?></p></div>
    <div class="author"><?= htmlspecialchars_decode(stripslashes($语音课程['详情'])) ?> </div><br><br><br>
    <div class="avatar"><a href="<?= $语音课程详情.'&id='.$value['id']?>">加入讨论</a></div>

</div>
<?php

?>

<div class="class_view_btn_start">


    <?php

    $时间冲突 = $bm->检测该用户重复报名($语音课程,$_GET['id']);
                 if($_SESSION['vo用户数据']['id'] ==$语音课程['讲课专家id']  ){
                     if(  date("Y-m-d H:i:s",(strtotime($语音课程['开始时间']) -3600*12)) <date("Y-m-d H:i:s")){
                         if($语音课程['状态'] ==='预备') { ?><input type='button' onclick='f修改课程状态("开始")' value='开始上课'>
                             <?php
                         }else if($语音课程['状态'] ==='开始') { ?><input type='button' onclick='f修改课程状态("结束")' value='结束上课'>
                             <?php
                         }
                     }

                 }else  {
                     if($当前用户已报名 && $语音课程['状态'] ==='预备') {?>

                         <input type="button" onclick="f报名('<?=$状态?>',<?=$当前用户已报名['id']?>)"     value="<?=$状态?>">
                         <?php

                     }
                 }


    ?>

</body>
</html>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>
<script src="../resource/js/hermes.js"></script>

<script>
    function f报名(状态,id){

        var 已报名 ='<?= $时间冲突 ?>';
        var 是否登陆 ='<?= $个人信息['密码']?>';
        if(是否登陆 == ''){
            alert('请先加入爱贝医生');
            window.location.href= '<?= $注册?>';
        }else{
            if(已报名 ==0){

                $.post('agent_manages.php',{'报名id':id,"状态":状态,'课程id':<?=$_GET['id']?>,'参数':'修改报名语音课程'},function(data) {
                    if(data){
                        if(状态=='取消报名') alert("取消报名成功!");
                        else alert("报名成功!");
                        location.replace(location.href='');

                    }else {
                        alert("报名失败!");
                    }
                });
            }else{
                alert('同一时间内您已报名其他课程');
            }


        }



    }

    function f修改课程状态(状态){
        $.post('agent_manages.php',{'课程id':'<?= $_GET['id']?>',"状态":状态,'参数':'修改课程状态'},function(data){

            if(data){
                alert(状态+"课程成功!");
               // WeixinJSBridge.call('closeWindow');
                 location.replace(location.href);
            }else {
                alert(状态+"课程失败!");
            }
        });
    }



</script>
